﻿<%@ WebHandler Language="C#" Class="Login" %>

using System;
using System.Data;
using System.Web;
using System.Collections;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Configuration;
using System.Text;
using System.Xml;

public class Login : IHttpHandler 
{
    public void ProcessRequest (HttpContext context) 
    {
        if (System.Web.HttpContext.Current.Request["modeType"] != null)
        {
            if (System.Web.HttpContext.Current.Request["modeType"].ToString() == "xml")
            {
                context.Response.ContentType = "application/xml";
            }
        }
        else
        context.Response.ContentType = "text/plain";
        context.Response.Buffer = true;
        context.Response.ExpiresAbsolute = DateTime.Now.AddDays(-1);
        context.Response.AddHeader("pragma", "no-cache");
        context.Response.AddHeader("cache-control", "");
        context.Response.CacheControl = "no-cache";

        string result = "";
        string p_MothodName = QueryValue("MothodName");
        result = GetPageData(p_MothodName);
        context.Response.Write(result);
    }

    private string GetPageData(string p_MothedName)
    {
        //根據方法名用於區分調用不同的類文件的公共入口
        switch (p_MothedName)
        {
            case "CheckPwdCard":
                {
                    return new BusWEB.WFInterface.Users().NeedDynamicPwd(QueryValue("loginName"));
                }
            default:
                return "";
        }
    }
    
    private string QueryValue(string p_key)
    {
        if (System.Web.HttpContext.Current.Request.Params[p_key] != null)
            return System.Web.HttpContext.Current.Request.Params[p_key];
        else
            return "";
    }
    
    public bool IsReusable 
    {
        get {
            return false;
        }
    }
    private System.Xml.XmlDocument QueryXmlDocu()
    {
        System.Xml.XmlDocument xd2 = new System.Xml.XmlDocument();
        if (System.Web.HttpContext.Current.Request["modeType"] == "xml")
        {
            try
            {
                System.Web.HttpContext.Current.Response.ContentType = "application/xml";
                xd2.Load(System.Web.HttpContext.Current.Request.InputStream);
                return xd2;
            }
            catch (Exception ex)
            {
                System.Web.HttpContext.Current.Response.ContentType = "text/plain";
                System.Web.HttpContext.Current.Response.Write(ex.Message);
                System.Web.HttpContext.Current.Response.End();
                return new System.Xml.XmlDocument();
            }

        }
        else
            return new System.Xml.XmlDocument();
    }
}